﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using ProjectCore.Application;
using ProjectCore.Application.AppUser.Dto;
using ProjectCore.Domain.Model.Entity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace ProjectCore.WebApi.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class ProductController : ControllerBase
    {
        private readonly IAppProduct appProduct;
        public ProductController(IAppProduct _appAdmin)
        {
            appProduct = _appAdmin;
        }
        /// <summary>
        /// 获取商品表集合
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<ActionResult> GetProducts()
        {
            List<PproductType> pproductTypes = await appProduct.GetPproductTypes();
            return  Ok(new { data = pproductTypes });
        }


        /// <summary>
        /// 商品表逻辑删除
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult> IsDel(int Id)
        {
            int n =await appProduct.IsDel(Id);
            return Ok(new { data = n });
        }


        /// <summary>
        /// 商品表添加
        /// </summary>
        /// <param name="product"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult> Add(Product product)
        {
            int n =await appProduct.Add(product);
            return Ok(new { data = n });
        }


        /// <summary>
        /// 获取商品表数据
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ActionResult> GetProduct(int Id)
        {
            Product product =await appProduct.GetProduct(Id);
            return Ok(new { data = product });
        }


        /// <summary>
        /// 修改商品表数据
        /// </summary>
        /// <param name="product"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult> Upt(Product product)
        {
            int n =await appProduct.Upt(product);
            return Ok(new { data = n });
        }


        /// <summary>
        /// 汽车规格添加
        /// </summary>
        /// <param name="skuCar"></param>
        /// <returns></returns>
        [HttpPost]
        public  async Task<ActionResult> SkuCarAdd(SkuCar skuCar)
        {
            int n = await appProduct.SkuCarAdd(skuCar);
            return Ok(new
            {
                data = n
            });
        }


        /// <summary>
        /// 获取汽车规格数据
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        [HttpGet]
        public  async Task<ActionResult> GetCar(int Id)
        {
            SkuCar car = await appProduct.GetCar(Id);
            return Ok(new
            {
                data = car
            });
        }


        /// <summary>
        /// 修改汽车规格数据
        /// </summary>
        /// <param name="car"></param>
        /// <returns></returns>
        [HttpPost]
        public  async Task<ActionResult> SkuCarUpt(SkuCar car)
        {
            int n = await appProduct.SkuCarUpt(car);
            return Ok(new
            {
                data = n
            });
        }


        /// <summary>
        /// 手机规格添加
        /// </summary>
        /// <param name="phone"></param>
        /// <returns></returns>
        [HttpPost]
        public  async Task<ActionResult> SkuPhoneAdd(SkuPhone phone)
        {
            int n = await appProduct.SkuPhoneAdd(phone);
            return Ok(new
            {
                data = n
            });
        }


        /// <summary>
        /// 获取手机规格数据
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        [HttpGet]
        public  async Task<ActionResult> GetPhone(int Id)
        {
            SkuPhone phone = await appProduct.GetPhone(Id);
            return Ok(new
            {
                data = phone
            });
        }


        /// <summary>
        /// 修改手机规格数据
        /// </summary>
        /// <param name="phone"></param>
        /// <returns></returns>
        [HttpPost]
        public  async Task<ActionResult> SkuPhoneUpt(SkuPhone phone)
        {
            int n = await appProduct.SkuPhoneUpt(phone);
            return Ok(new
            {
                data = n
            });
        }


        /// <summary>
        /// 设置添加
        /// </summary>
        /// <param name="setting"></param>
        /// <returns></returns>
        [HttpPost]
        public  async Task<ActionResult> SettingAdd(Setting setting)
        {
            int n = await appProduct.SettingAdd(setting);
            return Ok(new
            {
                data = n
            });
        }


        /// <summary>
        /// 获取设置数据
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        [HttpGet]
        public  async Task<ActionResult> GetSetting(int Id)
        {
            Setting setting = await appProduct.GetSetting(Id);
            return Ok(new
            {
                data = setting
            });
        }


        /// <summary>
        /// 修改设置数据
        /// </summary>
        /// <param name="setting"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult> SettingUpt(Setting setting)
        {
            int n = await appProduct.SettingUpt(setting);
            return Ok(new
            {
                data = n
            });
        }
    }
}
